package com.beiding.objectanalyzer;

import java.util.ArrayList;
import java.util.List;

/*
    分析键

    分析键以根对象id为

    不对null处理

 */
public class AnalyzeKey {

    private KeyNode endNode;

    public void setEndNode(KeyNode endNode) {
        this.endNode = endNode;
    }

    public KeyNode getEndNode() {
        return endNode;
    }

    @Override
    public String toString() {

        List<KeyNode> list = new ArrayList<>();

        KeyNode n = endNode;

        while (n!=null) {
            list.add(n);
            n = n.getHolderNode();
        }

        StringBuilder builder = new StringBuilder();

        builder.append(list.get(list.size() - 1));
        for (int i = list.size() - 2; i > -1; i--) {

            builder.append(".").append(list.get(i));
        }

        return builder.toString();
    }
}
